package com.itheima.dao;

import com.itheima.domain.Student;

public class StudentDao implements BaseStudentDao{
   private static Student [] stus=new Student[5];
    public boolean addStudent(Student stu) {
        int index=-1;

        for (int i = 0; i < stus.length; i++) {
            Student stus1 = stus[i];
            if(stus1==null){
                index=i;
                break;
            }
        }
        if(index==-1){
          return false;
        }else {
        return true;
        }
    }

    public Student[] findAllStudent() {

            return stus;
    }

    public void deletStudent(String sid) {
        int idex = getIdex(sid);
        stus[idex]=null;
    }
    public int getIdex(String sid){
        int index=-1;
        for (int i = 0; i < stus.length; i++) {
             Student stu=stus[i];
             if(stu!=null&&stu.getSid().equals(sid)){
                index=i;
             }
        }
        return index;
    }

    public void updateStudent(String sid, Student stu) {
        int idex = getIdex(sid);
        stus[idex]=stu;
    }
}
